﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SQLite;

namespace LevenBlog.Core.Install.Operations {
    public class SqliteDatatableInstall : IInstallOperation {
        #region IInstallOperation<object> Members

        public string Name {
            get { return CoreResource.install_sqlitedatatablecreate_name; }
        }

        public string Intro {
            get { return CoreResource.install_sqlitedatatablecreate_intro; }
        }

        public object Data {
            get;
            set;
        }

        public OperationResult Execute(OperationContext context) {
            List<string> errors = new List<string>();
            try {
                context.DbProvider.Command.Parameters.Clear();
                context.DbProvider.BeginTransaction();
                string[] array = CoreResource.install_sqlitedatatablecreate_script.Split(';');
                foreach (var item in array) {
                    context.DbProvider.Command.CommandText = item;
                    context.DbProvider.Command.ExecuteNonQuery();
                }
                context.DbProvider.Commit();
                context.DbProvider.Close();
            } catch (Exception e) {
                errors.Add(e.Message);
            }
            return new OperationResult(errors.Count > 0 ? false : true, errors);
        }

        #endregion
    }
}
